﻿using System;
using System.Reflection;
using DMS.Business.Modules.Knowledge;

namespace GMS.Web.Common.Services
{

    public partial class KnowledgeHandler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string methodName = Request.Params["method"];
            MethodInfo method = this.GetType().GetMethod(methodName);

            method.Invoke(this, null);
        }
        
        public void GetKnowledge()
        {
            string id = Request.Params["id"];
            string result = "{\"total\":\"1\", \"content\":\"@content\", \"title\":\"@title\"}";
            CommonKnowledge knowledge = KnowledgeService.GetKnowledge(id);
            string content = "";
            if (!String.IsNullOrEmpty(knowledge.Content))
                content = knowledge.Content;
            result = result.Replace("@content", content.Replace("\"", "'").Replace("\r\n", "")).Replace("@title", knowledge.Title);
            Response.Clear();
            Response.ContentType = "application/json";
            Response.Charset = "UTF-8";
            Response.Write(result);
            Response.End();
        }
    }
}